package com.pureut.equipment.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.equipment.domain.dto.InspectionWorkOrderDto;
import com.pureut.equipment.domain.vo.AuditVo;
import com.pureut.equipment.domain.vo.InspectionWorkOrderVo;
import com.pureut.equipment.service.InspectionWorkOrderService;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 *
 * Author:点检工单控制层
 * Date:2023/04/25 13:15
 * @DESC
 */
@RestController
@RequestMapping("/inspection-work-order")
public class InspectionWorkOrderController extends BaseController {

    /**
     * 点检工单service
     */
    @Resource
    InspectionWorkOrderService inspectionWorkOrderService;

    /**
     * 点检工单列表
     * @param inspectionWorkOrderVo
     * @return
     */
    @SaCheckPermission("device:spotCheck:workorder:list")
    @GetMapping("/list")
    public TableDataInfo<InspectionWorkOrderDto> list(InspectionWorkOrderVo inspectionWorkOrderVo, PageQuery pageQuery) {
        return inspectionWorkOrderService.getList(inspectionWorkOrderVo, pageQuery);
    }

    /**
     * 点检工单新增
     */
    @SaCheckPermission("device:spotCheck:workorder:add")
    @Log(title = "点检新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody InspectionWorkOrderVo inspectionWorkOrderVo) throws Exception {
        return toAjax(inspectionWorkOrderService.add(inspectionWorkOrderVo));
    }

    /**
     * 点检工单新增(当日触发调用)
     */
    @Log(title = "点检新增", businessType = BusinessType.INSERT)
    @PostMapping("/addToday")
    public R<Void> addToday(@RequestBody InspectionWorkOrderVo inspectionWorkOrderVo) throws Exception {
        return toAjax(inspectionWorkOrderService.addToday(inspectionWorkOrderVo));
    }

    /**
     * 点检工单新增（定时任务调用）
     */
    @Log(title = "点检新增", businessType = BusinessType.INSERT)
    @PostMapping("/schedulingAdd")
    public R<Void> schedulingAdd(@RequestBody InspectionWorkOrderVo inspectionWorkOrderVo) throws Exception {
        return toAjax(inspectionWorkOrderService.schedulingAdd(inspectionWorkOrderVo));
    }

    /**
     * 点检工单派工
     */
    @SaCheckPermission("device:spotCheck:workorder:dispatch")
    @Log(title = "保养工单派工", businessType = BusinessType.UPDATE)
    @PostMapping("/dispatch")
    public R<Void> dispatch(@RequestBody InspectionWorkOrderVo inspectionWorkOrderVo) throws Exception {
        return toAjax(inspectionWorkOrderService.dispatch(inspectionWorkOrderVo));
    }

    /**
     * 执行点检
     */
    @SaCheckPermission("device:spotCheck:workorder:maintenance")
    @Log(title = "执行保养", businessType = BusinessType.UPDATE)
    @PostMapping("/execute")
    public R<Void> execute(@RequestBody InspectionWorkOrderVo inspectionWorkOrderVo) throws Exception {
        return toAjax(inspectionWorkOrderService.execute(inspectionWorkOrderVo));
    }

    /**
     * 提交审核
     */
    @SaCheckPermission("device:spotCheck:workorder:review")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    @GetMapping("/audit/{id}")
    public R<Void> audit(@PathVariable("id") Long id) {
        return toAjax(inspectionWorkOrderService.audit(id));
    }

    /**
     * 撤销审核
     */
    @SaCheckPermission("device:spotCheck:workorder:revoke")
    @Log(title = "撤销审核", businessType = BusinessType.UPDATE)
    @GetMapping("/revocation/{id}")
    public R<Void> revocation(@PathVariable("id") Long id) {
        return toAjax(inspectionWorkOrderService.revocation(id));
    }

    /**
     * 单据审核
     */
    @SaCheckPermission("device:spotCheck:workorder:examine")
    @Log(title = "单据审核", businessType = BusinessType.UPDATE)
    @PostMapping("/documentAudit")
    public R<Void> documentAudit(@RequestBody AuditVo auditVo) throws Exception {
        return toAjax(inspectionWorkOrderService.documentAudit(auditVo));
    }

    /**
     * 修改
     */
    @SaCheckPermission("device:spotCheck:workorder:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping("/updateInspectionOrder")
    public R<Void> updateInspectionOrder(@RequestBody InspectionWorkOrderVo inspectionWorkOrderVo) {
        return toAjax(inspectionWorkOrderService.updateInspectionOrder(inspectionWorkOrderVo));
    }

    /**
     * 查看
     */
    @SaCheckPermission("device:spotCheck:workorder:query")
    @GetMapping("/getView/{id}")
    public R<InspectionWorkOrderDto> getView(@PathVariable("id") Long id) {
        return R.ok(inspectionWorkOrderService.getView(id));
    }

    /**
     * 删除
     */
    @SaCheckPermission("device:spotCheck:workorder:remove")
    @DeleteMapping("/deleteWorkOrder/{id}")
    public R<Void> deleteWorkOrder(@PathVariable("id") Long id) {
        return toAjax(inspectionWorkOrderService.deleteWorkOrder(id));
    }
}
